# -*- coding = utf-8 -*-
# @Time    : 2025/4/2 上午7:32
# @Author  : yqk
# @File    : 成绩查询.py
# @Software: PyCharm

import json
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from chaojiying_Python.chaojiying import Chaojiying_Client

# 配置Chrome选项
opt = Options()
opt.add_argument("--disable-blink-features=AutomationControlled")
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_experimental_option("detach", True)

service = Service(r'D:\python-code\chromedriver-win64\chromedriver.exe')

def login(url, username, password, soft_id):
    browser = webdriver.Chrome(service=service, options=opt)
    browser.get(url)
    time.sleep(3)
    #输入考生号
    browser.find_element(By.XPATH, '//*[@id="ksh"]').send_keys('11111111111111111')
    # 输入准考证号
    time.sleep(1)
    browser.find_element(By.XPATH, '//*[@id="zkzh"]').send_keys('11111111111111111')
    #输入身份证号
    time.sleep(1)
    browser.find_element(By.XPATH, '//*[@id="sfzh"]').send_keys('0000000000000000')
    time.sleep(1)
    #点击元素
    browser.find_element(By.XPATH, '//*[@id="input_ValidateCode"]').click()
    #获取验证码图片
    time.sleep(3)
    img = browser.find_element(By.XPATH, '//*[@id="ranImg"]').screenshot_as_png
    chaojiying = Chaojiying_Client(username, password, soft_id)
    code = chaojiying.PostPic(img, 1902)['pic_str']
    # print(code)
    browser.find_element(By.XPATH, '//*[@id="input_ValidateCode"]').send_keys(code)
    time.sleep(1)
    browser.find_element(By.XPATH, '//*[@id="detail"]/div[1]/div/div[6]/button').click()

if __name__ == '__main__':
    url = 'http://cx.sceea.cn/html/GZDZCJ.htm'
    with open(r'D:\python-code\chaojiying_Python\password.json', 'r',encoding='utf-8') as f:
        info = json.loads(f.read())
    password = info['password']
    username = info['username']
    soft_id = info['soft_id']
    login(url, username, password, soft_id)




